package com.ruoyi.common.core.domain;

import com.ruoyi.common.constant.HttpStatus;
import lombok.Data;

import java.util.HashMap;
import java.util.Map;

@Data
public class AjaxResultPlus /*extends AjaxResult*/{

    private Boolean success; // 操作结果

    private Integer code; // 返回状态码

    private String message; // 返回信息

    private Map<String,Object> data = new HashMap<>(); // 返回数据

    /*把构造方法私有*/
    private AjaxResultPlus(){}

    /*成功静态方法*/
    public static AjaxResultPlus success(){
        AjaxResultPlus r = new AjaxResultPlus();
        r.setSuccess(true);
        r.setCode(HttpStatus.SUCCESS);
        r.setMessage("成功");
        return r;
    }
    /*失败静态方法*/
    public static AjaxResultPlus error(){
        AjaxResultPlus r = new AjaxResultPlus();
        r.setSuccess(false);
        r.setCode(HttpStatus.ERROR);
        r.setMessage("失败");
        return r;
    }

    /*返回自身可以做到链式编程*/
    public AjaxResultPlus success(Boolean success){
        this.setSuccess(success);
        return this;
    }

    public AjaxResultPlus message(String message){
        this.setMessage(message);
        return this;
    }

    public AjaxResultPlus code(Integer code){
        this.setCode(code);
        return this;
    }

    public AjaxResultPlus data(String key,Object value){
        this.data.put(key,value);
        return this;
    }


}
/*
 *
 * @author Mr.Bao
 * @date 2021/8/14 23:53
 */